package com.example.administrator.nurse.widget;

import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;

/**
 * Created by Administrator on 2016/5/8.
 */
public class PagerSelectedListener implements ViewPager.OnPageChangeListener {
    private int offset;
    private int tabWidth;
    private int currentIndex=0;
    private View tabLine;

    public PagerSelectedListener(int offset,int tabWidth,View tabLine){
        this.offset=offset;
        this.tabWidth=tabWidth;
        this.tabLine=tabLine;
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        Animation animation=null;
        animation=new TranslateAnimation(currentIndex*(tabWidth+offset*2),position*(tabWidth+offset*2),0,0);
        currentIndex=position;
        animation.setFillAfter(true);
        animation.setDuration(300);
        tabLine.startAnimation(animation);
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
